﻿/*****************************************************************//**
 * @file    FITKGraphObjectConnectorAssignment.h
 * @brief   Dashed line graph object for connector assignment.
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-07-03
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTCONNECTORASSIGNMENT_H__
#define __FITKGRAPHOBJECTCONNECTORASSIGNMENT_H__

#include "FITKGraphObjectLineBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

// Forward declaration
class vtkUnstructuredGrid;
class vtkPoints;
class vtkStringArray;
class vtkTextProperty;
class vtkSelectVisiblePoints;
class vtkPointSetToLabelHierarchy;
class vtkPointSource;

class FITKPolyRenderStrategy;
class FITKGraphActor;
class FITKGraphActor2D;

namespace Exchange
{
    class FITKGraphObjectCoordinateInternal;
}

namespace Interface
{
    class FITKAbaConnectorAssignment;
    class FITKModelSet;
}

namespace Exchange
{
    /**
     * @brief   Dashed line graph object for connector assignment.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-07-03
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectConnectorAssignment : public FITKGraphObjectLineBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectConnectorAssignment, FITKGraphObjectLineBase);
        FITKCLASS(Exchange, FITKGraphObjectConnectorAssignment);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   connector: The connector assignment data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        FITKGraphObjectConnectorAssignment(AbaqusData::FITKDataCase* caseData, Interface::FITKAbaConnectorAssignment* connector);

        /**
         * @brief   Destructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        ~FITKGraphObjectConnectorAssignment();

        /**
         * @brief   Update the line data.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Update the visibility with data object's visibility.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-08-05
         */
        void updateVisibility() override;

        /**
         * @brief   Highlight the graph actors.[override]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void highlight(QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight the graph actors.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void disHighlight() override;

        /**
         * @brief   Set the visibility of this graph object.[override]
         * @param   visibility: The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void setVisible(bool visibility) override;

        /**
         * @brief   Set the render, which will add this graph object to itself.( for checking visibility )[override]
         * @param   render: The FITKGrapgRender
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void setFITKRender(Comp::FITKGraphRender* render) override;

        /**
         * @brief   Simplified the graph object if necessary.[override]
         * @param   enabled: Enabled simplified flag
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void simplified(bool enabled) override;

    private:
        /**
         * @brief   Initialize the actor and line data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void init();

        /**
         * @brief   Initialize the actor and properties.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void initActors();

        /**
         * @brief   Get the assembly set used by the connector.
         * @param   connector: The connector
         * @return  The set data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        Interface::FITKModelSet* getConnectorSet(Interface::FITKAbaConnectorAssignment* connector);

        /**
         * @brief   Generate the line poly data.
         * @param   connector: The connector assignment data object
         * @return  Is valid
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        bool generatePolyData(Interface::FITKAbaConnectorAssignment* connector);

        /**
         * @brief   Create the coodinate system graph objects.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-29
         */
        void generateCsys();

        /**
         * @brief   Generate the connector assignment actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void generateGraph();

        /**
         * @brief   Clear all data about lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void clearData();

        /**
         * @brief   Clear the coordinate graph objects.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-29
         */
        void clearCsysData();

        /**
         * @brief   Add a vertex and a vertex cell to the grid data.
         * @param   ugrid: The grid data
         * @param   points: The points data
         * @param   pt: The position
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        void addVertexCell(vtkUnstructuredGrid* ugrid, vtkPoints* points, double* pt);

        /**
         * @brief   Enable or disable visible points filter.
         * @param   enabled: Is enable
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-04
         */
        void enableVisiblePoints(bool enabled);

    private:
        /**
         * @brief   The lines information.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        QList<_LineInfo> m_lastLinesInfo;

        /**
         * @brief   The graph object of the coordinate 1.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-29
         */
        FITKGraphObjectCoordinateInternal* m_coordGraphObj_1{ nullptr };

        /**
         * @brief   The graph object of the coordinate 2.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-29
         */
        FITKGraphObjectCoordinateInternal* m_coordGraphObj_2{ nullptr };

        /**
         * @brief   The grid data for start points' glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkUnstructuredGrid* m_ugridStart{ nullptr };

        /**
         * @brief   The grid points for start points' glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkPoints* m_pointsStart{ nullptr };

        /**
         * @brief   The grid data for end points' glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkUnstructuredGrid* m_ugridEnd{ nullptr };

        /**
         * @brief   The grid points for end points' glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkPoints* m_pointsEnd{ nullptr };

        /**
         * @brief   The grid data for lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkUnstructuredGrid* m_ugridLine{ nullptr };

        /**
         * @brief   The grid points for lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkPoints* m_pointsLine{ nullptr };

        /**
         * @brief   The grid data for text label(s).
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkUnstructuredGrid* m_ugridLabel{ nullptr };

        /**
         * @brief   The grid points for text label(s).
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkPoints* m_pointsLabel{ nullptr };

        /**
         * @brief   The text array for text label(s).
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkStringArray* m_textArray{ nullptr };

        /**
         * @brief   The text property for the text label(s).
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkTextProperty* m_textProperty{ nullptr };

        /**
         * @brief   The point source for start points.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-17
         */
        vtkPointSource* m_pointSourceStart{ nullptr };

        /**
         * @brief   The stategy for the end points.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        FITKPolyRenderStrategy* m_strategyEnd{ nullptr };

        /**
         * @brief   The visible points filter for the end points' glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkSelectVisiblePoints* m_visiblePtEnd{ nullptr };

        /**
         * @brief   The visible points filter for the labels' points.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkSelectVisiblePoints* m_visiblePtText{ nullptr };

        /**
         * @brief   Label hierarchy for end points.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkPointSetToLabelHierarchy* m_labelHieEnd{ nullptr };

        /**
         * @brief   Label hierarchy for label(s).
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        vtkPointSetToLabelHierarchy* m_labelHieText{ nullptr };

        /**
         * @brief   The actor for start points' glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        FITKGraphActor* m_fActorStart{ nullptr };

        /**
         * @brief   The actor for end points' glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        FITKGraphActor2D* m_fActorEnd{ nullptr };

        /**
         * @brief   The actor for lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        FITKGraphActor* m_fActorLine{ nullptr };

        /**
         * @brief   The text label actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        FITKGraphActor2D* m_fActorLabel{ nullptr };

        /**
         * @brief   The label font size.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        double m_fontSize = 14.;

        /**
         * @brief   The shape size.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        double m_glyphSize = 30.;

        /**
         * @brief   The model( set ) id.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        int m_setId = -1;

        /**
         * @brief   The type name of the connector.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-03
         */
        QString m_typeName = "";

        /**
         * @brief   The data id of the coordinate system 1.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-29
         */
        int m_csysId_1 = -1;

        /**
         * @brief   The data id of the coordinate system 2.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-29
         */
        int m_csysId_2 = -1;

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTCONNECTORASSIGNMENT_H__
